<!-- 订单管理页面 -->
<template>
	<view>
		<!-- 顶部搜索框 -->
		<u-navbar :border-bottom='false'>
			<navigator class="search_box u-f-ac" hover-class="none" url="/pages/home/order-manage/order-search/order-search">
				<u-icon name="search" color="#cccccc" size="28"></u-icon>
				<text>搜索</text>
			</navigator>
		</u-navbar>
		<!-- tab及页面 -->
		<view class="tab-page">
			<view class="tab">
				<u-tabs :list="tabList" :is-scroll="false" :current="current" bar-width="120" @change="change" bg-color="#fff" style="padding: 20rpx 0;"></u-tabs>
			</view>
			<view class="page-content">
				<scroll-view class="scroll-view" scroll-y>
					<view v-for="(item,index) in orderList" :key="index">
						<!-- 订单管理基础模板 -->
						<view class="order-manage-card">
							<view class="top" @click='toOrderDeatil(item)'>
								<view class="top-number">
									<text>订单编号： </text><text class="number"> {{item.order_id}}</text>
								</view>
								<view class="top-state">
									<!-- 0待发货，1已取消，>1已发货 -->
									<text>{{item.deliver_state == 0 ? '待发货' : item.deliver_state == 1 ? '已取消' : '已发货'}}</text>
								</view>
							</view>
							<view class="content" @click='toOrderDeatil(item)'>
								<goods-info :data="item"></goods-info>
							</view>
							<view class="bottom">
								<view class="bottom-left">
									<text>{{$u.timeFormat(item.pay_time, 'yyyy-mm-dd hh:MM:ss')}}</text>
								</view>
								<view class="bottom-right" @click='toOrderDeatil(item)'>
									<button type="default" plain="true">查看详情</button>
								</view>
							</view>
						</view>
					</view>
				</scroll-view>
				<tui-no-data imgUrl="https://sbb-sbb.oss-cn-shenzhen.aliyuncs.com/Open_source_project/mine/empty_bg.png" v-if="noData1">暂无数据</tui-no-data>
				<view class="bootom-box">
					<load-more :visible="loadMore "></load-more>
					<om-nomore :visible="noMoreFlag && !noData1" bgcolor="#f9f9f9"></om-nomore>
				</view>
			</view>
		</view>
	</view>
	
</template>

<script>
	export default {
		data() {
			return {
				tabList: [
					{
						name: '待发货'
					},{
						name: '已发货'
					},{
						name: '全部'
					}
				],
				orderList:[],
				current: 0,           // 指定第一页为初始页面
				currentPage: 1,       //分页
				total: 0,             //数据总数
				loadMore: false,      //数据加载中
				noMoreFlag: false,    //没有更多数据了
				noData1: false,       //没有数据
				deliverState: 0,      //订单交付状态
			};
		},
		onLoad(e) {
			if(e.tab == 1){
				this.current = 1
			}
		},
		onShow() {
			this.clear();
			this.getOrder()
		},
		methods: {
			//顶部section改变
			change(index) {
				this.current = index;
				this.clear();
				this.getOrder()
			},
			//获得数据
			getOrder(){
				this.loadMore = true;
				//查询不同交付状态的订单    0为查待发货，1为查已发货，-1则代表查询全部
				this.deliverState = this.current == 2 ? '-1' : this.current.toString();
				this.$http.post('/api/auth/order/countryBusinGoodList',{businId: this.$store.state.userInfo.id,deliverState: this.deliverState,currentPage:this.currentPage}).then(res => {
					this.loadMore = false;
					this.total = res.data.total;
					if(this.total == 0) return this.noData1 = true;
					
					this.orderList = this.orderList.concat(res.data.rows)
				})
			},
			//跳转订单详情
			toOrderDeatil(item){
				this.$u.route('pages/home/order-manage/order-detail/order-detail');
				//先跳转页面，在通过嵌套$emit传数据
				uni.$once('need',() => {
					uni.$emit('detail',{
						busin_id: item.busin_id,
						order_id: item.order_id
					})
				})
			},
			//切换tab，重新请求，需清空原有数据
			clear(){
				this.orderList = [];
				this.noData1 = false;
				this.noMoreFlag = false;
				this.currentPage = 1;
				this.total = 0
			},
		},
		onReachBottom(){
			if(this.total == this.orderList.length) return this.noMoreFlag = true;
			this.currentPage++;
			this.getOrder()
		}
	};
</script>


<style lang="scss">
.tab-page{
	.tab{
		z-index: 2;
		position: fixed;
		width: 100vw;
	}
	.page-content{
		padding-top: 60rpx;
		height: calc(100% - 184rpx);
		.scroll-view{
			height: 100%;
		}
	}
}

.order-manage-card{
	margin: 30rpx 20rpx;
	padding: 30rpx 20rpx;
	height: 380rpx;
	border-radius: 20rpx;
	background-color: #fff;
	.top{
		display: flex;
		justify-content: space-between;
		padding: 10rpx 0;
		font-size: 13px;
		.top-number{
			.number{
				margin-left: 10rpx;
				font-size: 15px;
				font-weight: 700;
			}
		}
		.top-state{
			color:#2ba4f7;
		}
		
	}
	.content{
		margin: 30rpx 0;
		.content-foot{
			display: flex;
			flex-direction: row-reverse;
			align-items: center;
			text{
				color:#aaa7a0;
			}
			.total{
				margin-left: 10rpx;
				color: #000;
				font-size: 16px;
				font-weight: 700;
			}
			
		}
		
	}
	.bottom{
		display: flex;
		align-items: center;
		justify-content: space-between;
		.bottom-left{
			// margin-left: 20rpx;
			color: #bebebe;
		}
		.bottom-right{
			button{
				margin-left: 20rpx;
				width: 200rpx;
				height: 60rpx;
				font-size: 14px;
				line-height: 60rpx;
				color: #2ba4f7;
				border: none;
				border-radius: 40rpx;
				background-color: #f7f7f7;
			}
		}
	}
}

.bootom-box{
	height: 160rpx;
}
</style>


